using UnityEngine;
using System.Collections;

public class CheckPoint : WorldObject {
	
	public GameObject mainCharacter;
	public int index{get; set;}
	//private Vector3 _moveDirection, _verticalDirection;
	private bool _isCurrCheckpnt;
	void Start () 
	{
		rayLength = CheckPointMgr.Instance.rayLength;//5.0f;
		base.Start();
		CheckPointMgr.Instance.RegisterCheckpoints(this);
	}
	
	void Update () 
	{
		if(IsMainCharacterPassingByRange())
		{
			CheckPointMgr.Instance.UpdateCurrentCKP(index);
		//	Debug.Log(gameObject.name + " updated");
		}
	}
	
	void PlayAnim()
	{
		
	}
	
	public void Respawn()
	{
		StartCoroutine(PauseBeforeSpawn());
	}
	
	IEnumerator PauseBeforeSpawn()
	{
//		Debug.Log("respawn at checkpnt");
		CameraMovment.Instance.SetCameraToRespawnPoint(transform.position.x, transform.position.y);
		yield return new WaitForSeconds(1.0f);
		GameObject main = Instantiate(mainCharacter, transform.position, Quaternion.identity) as GameObject;
		main.GetComponent<MainCharacterController>().moveDirection = moveDirection;
		main.GetComponent<MainCharacterController>().verticalDirection = verticalDirection;
		main.GetComponent<MainCharacterController>().isClockwise = isClockwise;
		CameraMovment.Instance.SetMainCtrl(main.GetComponent<MainCharacterController>());
	}
	
//	void OnTriggerEnter(Collider col){
//		//Debug.Log("on trigger enter");
//		_isCurrCheckpnt = true;
//	}
//	
//	void OnTriggerStay(Collider col){
//		//Debug.Log("on trigger stay");
//		_isCurrCheckpnt = true;
//	}
//	
//	void OnTriggerExit(Collider col){
//		_isCurrCheckpnt = false;
//	}
}
